import os
import xlrd
import sys
import django
from xlrd import xldate_as_tuple

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")
django.setup()
from apps.supply_order.models import Goods
from apps.supply_order.models import Category

"""
更新我买网的价格
"""
"""
Goods matching query does not exist.
668550 【自营】瑞锦成武夷山正山小种250g/盒
Goods matching query does not exist.
570412 【中粮海外直采】杰克布森精彩哥本哈根丹麦黄油曲奇饼干908g （丹麦进口 盒）
Goods matching query does not exist.
661681 【自营】丽兹特级初榨橄榄油750ml（西班牙进口 瓶）
Goods matching query does not exist.
636056 【专仓直发包邮】2018头茬黑玉米东方天谷山西新鲜甜糯玉米黑玉米棒180g*10根
Goods matching query does not exist.
669206 【专仓直发包邮】云南榆黄菇菌当季鲜品净重2斤顺丰包邮
Goods matching query does not exist.
669203 【专仓直发包邮】云南姬松茸菌当季鲜品净重2斤顺丰包邮
Goods matching query does not exist.
623510 【专仓直发包邮】泰国椰青2枚买2份送开椰器泰国椰青2粒
Goods matching query does not exist.
616176 【专仓直发包邮】裕亨顺沁州黄小米3kg礼盒
Goods matching query does not exist.
659456 【专仓直发包邮】琪悦头茬山西黑糯玉米220g*6根装
Goods matching query does not exist.
613326 【专仓直发】卡露伽海博瑞鲟鱼子酱/鱼籽酱10g高端食品食材
Goods matching query does not exist.
582311 【专仓直发包邮】八马茶叶乌龙茶黄金桂散装袋装250gAA1215
Goods matching query does not exist.
603146 【专仓直发包邮】六神花露水95ML
Goods matching query does not exist.
673052 【礼券】星农联合环球进口海鲜1888型8种
Goods matching query does not exist.
613343 海知己金钩海米170g/罐野生虾米熬汤做菜提鲜必备
Goods matching query does not exist.
656927 【专仓直发包邮】博乐天单晶冰糖冰糖块400g*4袋
Goods matching query does not exist.
665175 【专仓直发包邮】餚珍堂无公害鲜活甲鱼400g-550g/只盒装
Goods matching query does not exist.
670666 【自营】【安萃】精品红颜草莓 盒装400g 12-15粒 单果20g-30g左右 Y
Goods matching query does not exist.
616992 【自营】五羊 孕妇温和雪肌面膜23ml/片/新老包装随机
Goods matching query does not exist.
622311 【中粮直采】德国 莱茵黑森 彼得·温特 P·W 雷司令干型白葡萄酒 750ML
Goods matching query does not exist.
622307 【中粮直采】德国|莱茵黑森 彼得·温特 P·W 黑皮诺干型葡萄酒 750ml
Goods matching query does not exist.
622308 【中粮直采】德国|莱茵黑森 彼得·温特酒窖卡塔琳娜黑皮诺半甜型红葡萄酒 瓶750ml
Goods matching query does not exist.
622306 【中粮直采】德国 莱茵黑森 彼得·温特 P·W 雷司令半甜型白葡萄酒750ML
"""


def update_price_wm(xlsx):
    data = xlrd.open_workbook(xlsx)  # 打开excel
    table = data.sheets()[0]
    rows = table.nrows  # 行数
    for i in range(1, rows):
        row_values = table.row_values(i)  # 某一行数据
        ck_name = row_values[0]  # 1、仓库名称
        goodsid = int(row_values[1])  # 商品编码
        goodsname = row_values[2]  # 商品名称
        cost = int(row_values[3] * 100)  # 供应价
        sales_price = int(row_values[4] * 100)  # 平台价
        sales_price_isvip = int(row_values[5] * 100)  # 会员价
        system_category = row_values[6]  # 分类
        # print(ck_name, goodsid, goodsname, cost, sales_price)
        try:
            goods_obj = Goods.objects.get(goodsid=goodsid)
            if ck_name == "包邮":
                post_fee = 0
            else:
                post_fee = 1000
            if goods_obj.pubflag == 1 or goods_obj.pubflag == "1":
                goods_obj.can_sale = True
            goods_obj.post_fee = post_fee
            goods_obj.cost = cost
            goods_obj.sales_price_isvip = sales_price_isvip
            goods_obj.sales_price = sales_price
            goods_obj.system_category = Category.objects.get(name=system_category)
            goods_obj.save()
        except Exception as e:
            print(e)
            print(goodsid, goodsname)


if __name__ == '__main__':
    update_price_wm("goods_price.xls")
    pass
